lets_plot.plot.core.PlotSpec

class lets_plot.plot.core.PlotSpec(data, mapping, scales, layers, **kwargs)

A class of the initial plot object.

Do not use this class explicitly.

Instead you should construct its objects with functions ggplot(), corr_plot(…).points().build() etc.

__init__(data, mapping, scales, layers, **kwargs)

Initialize self.

get_plot_shared_data()

Extracts the data shared by all layers.

Returns

Object data.

Return type

dict or DataFrame

Examples

1
2
3
4
5
from lets_plot import *
LetsPlot.setup_html()
p = ggplot({'x': [0], 'y': [0]}, aes('x', 'y'))
p += geom_point(data={'x': [1], 'y': [1]})
p.get_plot_shared_data()
{'x': [0], 'y': [0]}
has_layers()bool

Checks if the PlotSpec object has at least one layer.

Returns

True if object has layers.

Return type

bool

Examples

1
2
3
4
5
6
from lets_plot import *
LetsPlot.setup_html()
p = ggplot()
print(p.has_layers())
p += geom_point(x=0, y=0)
print(p.has_layers())
False
True
__add__(other)

Allows to add different specs to the PlotSpec object.

Examples

1
2
3
4
5
6
7
from lets_plot import *
LetsPlot.setup_html()
p = ggplot({'x': [0, 1, 2], 'y': [0, 1, 2]}, aes('x', 'y'))
l = layer('point', mapping=aes(color='x'))
s = scale_color_discrete()
t = theme(axis_title='blank')
p + l + s + t
as_dict()

Returns the dictionary of all properties of the object with as_dict() applied recursively to all subproperties of FeatureSpec type.

Returns

Dictionary of properties.

Return type

dict

Examples

1
2
3
4
from lets_plot import *
LetsPlot.setup_html()
p = ggplot({'x': [0], 'y': [0]}) + geom_point(aes('x', 'y'))
p.as_dict()
{'data': {'x': [0], 'y': [0]},
 'mapping': {'x': None, 'y': None},
 'data_meta': {},
 'kind': 'plot',
 'scales': [],
 'layers': [{'geom': 'point',
   'stat': None,
   'data': None,
   'mapping': {'x': 'x', 'y': 'y'},
   'position': None,
   'show_legend': None,
   'sampling': None,
   'tooltips': None,
   'data_meta': {},
   'map': None,
   'map_join': None}]}
show()

Draws a plot.

Examples

1
2
3
4
from lets_plot import *
LetsPlot.setup_html()
p = ggplot() + geom_point(x=0, y=0)
p.show()
props()

Returns the dictionary of all properties of the object in their initial form.

Returns

Dictionary of properties.

Return type

dict

Examples

1
2
3
4
from lets_plot import *
LetsPlot.setup_html()
p = ggplot({'x': [0], 'y': [0]}) + geom_point(aes('x', 'y'))
p.props()
{'data': {'x': [0], 'y': [0]},
 'mapping': <lets_plot.plot.core.FeatureSpec at 0x9d53648>,
 'data_meta': {}}